<template>
    <div>
        <div class="container" id="WayID">
            <el-card class="box-card">
                <el-form :inline="true"class="demo-form-inline">
                    <el-form-item label="姓名">
                        <el-input v-model.trim="name" placeholder="姓名"></el-input>
                    </el-form-item>
                    <el-form-item label="工号" style="margin-left: -15px">
                        <el-input v-model.trim="jobNumber" placeholder="工号"></el-input>
                    </el-form-item>
                    <el-form-item label="园区" style="margin-left: -15px">
                        <el-select v-model="gardenId" placeholder="园区"  @change="currentSel($event)">
                            <el-option label="全部" value=""></el-option>
                            <el-option v-for="(item,index) in areaList"
                                       :label="item.name"
                                       :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="区域" style="margin-left: -15px">
                        <el-select v-model="areaId" placeholder="区域" >
                            <el-option label="全部" value=""></el-option>
                            <el-option v-for="item in qvList" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="时间" style="margin-left: -15px">
                        <el-date-picker
                                value-format="yyyy-MM-dd"
                                v-model="value1"
                                type="daterange"
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" @click="handleSearch" style="margin-left: 190px">搜索</el-button>
                    </el-form-item>
                        <el-button
                                style="margin-left: 140px;"
                                type="success"
                                @click="leadingOut">导出
                        </el-button>


                </el-form>
            </el-card>
            <iframe :src="iframesrc" style="display: none"></iframe>

            <!--<div class="handle-box">-->
                <!--<el-button-->
                <!--type="primary"-->
                <!--icon="el-icon-delete"-->
                <!--class="handle-del mr10"-->
                <!--@click="delAllSelection"-->
                <!--&gt;批量删除</el-button>-->
                <!--<el-select v-model="query.address" placeholder="地址" class="handle-select mr10">-->
                <!--<el-option key="1" label="广东省" value="广东省"></el-option>-->
                <!--<el-option key="2" label="湖南省" value="湖南省"></el-option>-->
                <!--</el-select>-->
            <!--</div>-->
            <el-card class="box-card">
                <el-table
                        v-loading="loading"
                        :data="tableData"
                        border
                        class="table"
                        ref="multipleTable"
                        header-cell-class-name="table-header"
                        @selection-change="handleSelectionChange"
                >
                    <el-table-column
                            type="index"
                            width="50">
                    </el-table-column>
                    <el-table-column prop="jobNumber" label="工号"></el-table-column>
                    <el-table-column prop="name" label="姓名"></el-table-column>
                    <el-table-column prop="garden" label="园区"></el-table-column>
                    <el-table-column prop="area" label="区域"></el-table-column>
                    <el-table-column  label="时间">
                        <template slot-scope="scope">
                            {{$moment(scope.row.time).format('YYYY-MM-DD HH:mm:ss')}}
                        </template>

                    </el-table-column>
                    <!--<el-table-column label="发起时间" >-->
                    <!--<template slot-scope="scope"><div>{{scope.row.taskCreateTime}}</div> </template>-->
                    <!--</el-table-column>-->
                    <!--<el-table-column label="合同创建时间" align="center">-->
                    <!--<template slot-scope="scope"><div>{{scope.row.proCreateTime}}</div> </template>-->
                    <!--</el-table-column>-->
                    <!--<el-table-column label="状态" align="center">-->
                    <!--<template slot-scope="scope">-->
                    <!--<el-tag-->
                    <!--:type="scope.row.state==='成功'?'success':(scope.row.state==='失败'?'danger':'')"-->
                    <!--&gt;{{scope.row.state}}</el-tag>-->
                    <!--</template>-->
                    <!--</el-table-column>-->

                    <!--<el-table-column prop="date" label="注册时间"></el-table-column>-->
                    <!--<el-table-column label="操作" width="180" align="center">-->
                    <!--<template slot-scope="scope">-->
                    <!--<el-button-->
                    <!--type="text"-->
                    <!--icon="el-icon-edit"-->
                    <!--@click="handleEdit(scope.$index, scope.row)"-->
                    <!--&gt;详情</el-button>-->
                    <!--&lt;!&ndash;<el-button&ndash;&gt;-->
                    <!--&lt;!&ndash;type="text"&ndash;&gt;-->
                    <!--&lt;!&ndash;icon="el-icon-delete"&ndash;&gt;-->
                    <!--&lt;!&ndash;class="red"&ndash;&gt;-->
                    <!--&lt;!&ndash;@click="handleDelete(scope.$index, scope.row)"&ndash;&gt;-->
                    <!--&lt;!&ndash;&gt;删除</el-button>&ndash;&gt;-->
                    <!--</template>-->
                    <!--</el-table-column>-->
                </el-table>
                <div class="pagination">
                    <el-pagination
                            background
                            layout="total, prev, pager, next"
                            :current-page="query.pageIndex"
                            :page-size="query.pageSize"
                            :total="pageTotal"
                            @current-change="handlePageChange"
                    ></el-pagination>
                </div>
            </el-card>
            <div style="display: none">{{changeGardenId}}</div>
            <div style="display: none">{{timeMead}}</div>
        </div>

        <!--&lt;!&ndash; 编辑弹出框 &ndash;&gt;-->
        <!--<el-dialog title="编辑" :visible.sync="editVisible" width="30%">-->
        <!--<el-form ref="form" :model="form" label-width="70px">-->
        <!--<el-form-item label="用户名">-->
        <!--<el-input v-model="form.name"></el-input>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="地址">-->
        <!--<el-input v-model="form.address"></el-input>-->
        <!--</el-form-item>-->
        <!--</el-form>-->
        <!--<span slot="footer" class="dialog-footer">-->
        <!--<el-button @click="editVisible = false">取 消</el-button>-->
        <!--<el-button type="primary" @click="saveEdit">确 定</el-button>-->
        <!--</span>-->
        <!--</el-dialog>-->
    </div>
</template>

<script>
    import baseUrl from "../../config/baseUrl";

    export default {
        name: 'basetable',
        data() {
            return {
                iframesrc:'',
                myhref:'',
                report:'',
                qvList:[],
                areaList:[],
                value1:[],
                name:'',//人员名称
                jobNumber:'',//人员名称
                gardenName:'',
                gardenId:'',
                areaId:'',
                areaName:'',
                startTime:'',
                endTime:'',
                query: {
                    pageIndex: 1,
                    pageSize: 10
                },
                loading:true,
                tableData: [],
                multipleSelection: [],
                delList: [],
                editVisible: false,
                pageTotal: 0,
                form: {},
                idx: -1,
                id: -1
            };
        },
        created() {
            // ddbase.getAuthCode().then((res)=>{
            //
            // })
            //A0038335 单单
            //A0037835 大成哥
            this.value1[0]=this.$moment().format('YYYY-MM-DD')
            this.value1[1]=this.$moment().format('YYYY-MM-DD')
        },
        mounted(){
           this.getData()
            this.getTree()
        },
        computed:{
            changeGardenId(){
                if(this.gardenId==''){
                    this.qvList=[]
                    this.areaId=''
                }else {
                    let des =this.areaList.filter((currentValue)=>{ return currentValue.id == this.gardenId;})
                    console.log(des)
                    this.qvList= des[0].areaList
                }
            },
            timeMead(){
                this.startTime=this.value1[0]+' 00:00:00'
                this.endTime =this.value1[1]+' 23:59:59'
                console.log( this.startTime)
                return ''
            }
        },
        methods: {
            currentSel(e){
                console.log(e)
            },
            getTree(){
                this.$api.tree({}).then((res)=>{
                    console.log(".................")
                    console.log(res)
                    this.areaList =res.data
                })
            },
            // 获取 easy-mock 的模拟数据
            getData() {
                this.loading=true;
                const myData ={
                    name:this.name,
                    jobNumber:this.jobNumber,
                    gardenId:this.gardenId,
                    areaId:this.areaId,
                    startTime:this.startTime,
                    endTime:this.endTime,
                    pageNo: this.query.pageIndex,
                    pageSize: this.query.pageSize
                }
                this.$api.hpAreaGoTrack(myData).then((res)=>{
                    console.log(res)
                    this.tableData= res.data.records
                    this.pageTotal= parseInt(res.data.total)
                    this.loading=false
                }).catch((err)=>{
                    console.log(err)
                    this.loading=false
                })
            },
            // 触发搜索按钮
            handleSearch() {
                this.$set(this.query, 'pageIndex', 1);
                this.getData();
            },
            leadingOut(){
                // this.loading=true;
                const myData ={
                    name:this.name,
                    jobNumber:this.jobNumber,
                    gardenId:this.gardenId,
                    areaId:this.areaId,
                    startTime:this.startTime,
                    endTime:this.endTime,
                    // startTime:"2020-7-22 23:59:59",
                    // endTime:"2020-7-23 00:00:00",
                };
                // let a = document.createElement('a');
                // console.log()
                // var _str = "?";
                // for(var o in myData){
                //     if(myData[o] != -1){
                //         _str += o + "=" + myData[o] + "&";
                //     }
                // }
                // // var str = _str.replace(/\s+/g,"");
                let href =baseUrl+"/manager/hpAreaGoTrack/reportTrack";
                // this.export(href,myData)
                // console.log(href)
                // a.href =href
                // a.target = '_blank'
                // let ev =new MouseEvent('click');
                // a.dispatchEvent(ev)
                this.export(href,myData)

            },
            export (url, params) {
                let queryStr = '?1=1'
                if (params) {
                    for (let i in params) {
                        queryStr += `&${i}=${params[i]}`
                    }
                }
                console.log('导出参数：', params);
                var ele = document.createElement('a');
                ele.style.display = 'none';
                ele.href = url+queryStr;
                // 触发点击
                document.body.appendChild(ele);
                ele.click();
                // 然后移除
                document.body.removeChild(ele);
            },
            params(myData){
                return Object.keys(myData).map(function (key) {
                    return encodeURIComponent(key) + "=" + encodeURIComponent(myData[key])||' '
                }).join("&");
            },
            // 删除操作
            handleDelete(index, row) {
                // 二次确认删除
                this.$confirm('确定要删除吗？', '提示', {
                    type: 'warning'
                })
                    .then(() => {
                        this.$message.success('删除成功');
                        this.tableData.splice(index, 1);
                    })
                    .catch(() => {});
            },
            // 多选操作
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            delAllSelection() {
                const length = this.multipleSelection.length;
                let str = '';
                this.delList = this.delList.concat(this.multipleSelection);
                for (let i = 0; i < length; i++) {
                    str += this.multipleSelection[i].name + ' ';
                }
                this.$message.error(`删除了${str}`);
                this.multipleSelection = [];
            },
            // 编辑操作
            handleEdit(index, row) {
                this.idx = index;
                this.form = row;
                this.editVisible = true;
            },
            // 保存编辑
            saveEdit() {
                this.editVisible = false;
                this.$message.success(`修改第 ${this.idx + 1} 行成功`);
                this.$set(this.tableData, this.idx, this.form);
            },
            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageIndex', val);
                this.getData();
            }
        }
    };
</script>
<style>
    #WayID .el-form-item__content{
        width: 130px;
    }
    .el-card__body{
        background: #232343;
    }
    .el-table__empty-block{
        background: #232343;
        color: white;
    }
    .el-table__empty-text{
        color: white;
    }

    /*#WayID .el-form-item__content{*/
    /*    margin-left: 84px;*/
    /*}*/
    #WayID .el-form-item__label {
        width: 50px;
    }
    #WayID .el-table td .el-table th.is-leaf{
        background: #232343;
        border: none;
        color: white;
    }
    #WayID .el-table__row{
        background: #232343;
        border: none;
        color: white;
    }
    #WayID .el-card__body{
        background: #232343;
        border: none;
        color: white;
    }
    #WayID  .is-leaf{
        background: #232343;
        border-color: #232343;
        border: none;
        color: white;
    }
    .el-card{
        border: none !important;
    }
    .el-input{
        width: 130px;
    }
    .el-table__expanded-cell{
        background: #232343;
    }
    .el-table__header-wrapper{
        background: #232343;
    }
    .el-range-input{
        background: #232343;
        color: white;
    }
    .el-input__inner{
        background: rgb(41,41,86);
        border: none;
        color: white;
    }
    .is-scrolling-none{
        background: #232343;
    }
    .el-table--enable-row-transition .el-table__body td{
        border: none;
    }
    .el-table::before{
        background: #232343;
    }
    .el-table tbody tr:hover>td {
        background-color: #232343 !important
    }
    .el-table th, .el-table tr {
        background-color: #232343;
    }
    .el-table--enable-row-hover{
        border: none;
    }
    .el-table--border::after, .el-table--group::after{
        background-color: #232343;
    }
</style>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .table {
        width: 100%;
        font-size: 14px;
    }
    .red {
        color: #ff0000;
    }
    .mr10 {
        margin-right: 10px;
    }
    .table-td-thumb {
        display: block;
        margin: auto;
        width: 40px;
        height: 40px;
    }
</style>
